<?php

namespace App\Http\Controllers\XhApi;

use App\Repository\XhApi\GoodsRepository;
use Illuminate\Http\Request;


class GoodsController extends BaseController
{
    public $repoist;

    public function __construct(GoodsRepository $Repository)
    {
        $this->repoist = $Repository;
    }

    public function index(Request $request)
    {
        $params = $request->all();
        return $this->repoist->index($params, $request->get('pageNum'), 10);
    }

    public function list(Request $request)
    {
        $params = $request->all();
        return $this->repoist->goodsList($params, $request->get('pageNum'), 10);
    }

    public function detail(Request $request)
    {
        $id = $request->get('id');
        if (empty($id)) {
            return $this->returnMsg(20, '查询异常');
        }
        $data = $this->repoist->detail($id);
        if ($data['code'] == 200) {
            $item = [];
            foreach (config('xh.ruleType') as $k => $v) {
                $item = array_merge($item, $v['symbol']);
            }
            $apiSymbol = config('xh.apiSymbol');
            $item = array_merge($apiSymbol, $item);
            $data["ruleTypeList"] = array_unique($item);
        }
        return $data;
    }

    public function search(Request $request)
    {
        // echo 1111111;
        return $this->repoist->searchNumber($request->all(), $request->get('pageNum'));
    }

    public function buy(Request $request)
    {
        $id = $request->get('goodsId');
        if (empty($id)) {
            return $this->returnMsg(20, '查询异常');
        }
        $data = $this->repoist->buy($request->all());
        if ($data['code'] == 200) {
            $data["bookingTips"] = '预约不需要在线支付；预约成功后，客服首先核实号码，然后确定是否交易。用户可以随时取消订单，不承担任何费用。未满18岁的未成年人无法通过运营商实名办卡。';
            $data["buyTipsPic"] = [
                // 'https://card.qqinfor.com/static/xh/process-new.png',
                // 'https://card.qqinfor.com/static/xh/notice.png',
            ];
        }
        return $data;
    }

    public function searchOptions(Request $request)
    {
        $data = [
            'operatorType' => config('card.operatorType'),
            'ruleType' => config('xh.ruleType'),
            'sortTypList' => [
                0 => '默认排序',
                1 => '价格从低到高',
                2 => '价格从高到低'
            ],
            'salePriceList' => [
                ['name' => '售价:0元', 'min' => 0, 'max' => 0],
                ['name' => '售价:0-200元', 'min' => 0, 'max' => 200],
                ['name' => '售价:200元-500元', 'min' => 200, 'max' => 500],
                ['name' => '售价:500元-1000元', 'min' => 500, 'max' => 1000],
                ['name' => '售价:1000元-2000元', 'min' => 1000, 'max' => 2000],
                ['name' => '售价:1000元-2000元', 'min' => 1000, 'max' => 2000],
                ['name' => '售价:2000元-5000元', 'min' => 2000, 'max' => 5000],
                ['name' => '售价:5000元-10000元', 'min' => 5000, 'max' => 10000],
                ['name' => '售价:10000元-20000元', 'min' => 10000, 'max' => 20000],
                ['name' => '售价:20000以上', 'min' => 20001, 'max' => 900000000],
            ],
            'spendingList' => [
                ['name' => '0元', 'min' => 0, 'max' => 0],
                ['name' => '30以内', 'min' => 0, 'max' => 30],
                ['name' => '50以内', 'min' => 0, 'max' => 50],
                ['name' => '100以内', 'min' => 0, 'max' => 100],
                ['name' => '200以内', 'min' => 0, 'max' => 200],
                ['name' => '300以内', 'min' => 0, 'max' => 300],
                ['name' => '400以内', 'min' => 0, 'max' => 400],
                ['name' => '400以上', 'min' => 400, 'max' => 1000000],
            ]
        ];
        return $this->returnMsg(200, '数据已返回', $data);
    }
}
